package com.xianzhiOA.service.impl;/**
 * Created by Administrator on 2017/4/27.
 */

import com.github.pagehelper.PageHelper;
import com.xianzhiOA.bean.XzRole;
import com.xianzhiOA.dao.XzRoleMapper;
import com.xianzhiOA.service.XzRoleService;
import com.xianzhiOA.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 角色的业务层
 *
 * @author 甘汝雷
 * @create 2017-04-27 15:58
 **/
@Service("xzRoleService")
public class XzRoleServiceImpl implements XzRoleService {
    @Autowired
    private XzRoleMapper roleMapper;
    @Override
    public int addRole(XzRole role) {
        return roleMapper.insert(role);
    }

    @Override
    public List<XzRole> selRoleAll(XzRole role) {
        return roleMapper.selRoleAll(myMap(role));
    }
    @Override
    public PageBean<XzRole> selRoleAll(XzRole role, int page, int rows, Date beginDate, Date endDate) {
        PageHelper.startPage(page, rows);
        Map<String,Object> map = myMap(role);
        if (beginDate != null) map.put("beginDate",beginDate);
        if (endDate != null) map.put("endDate",endDate);
        List<XzRole> roleList = roleMapper.selRoleAll(map);
        PageBean<XzRole> pageBean = new PageBean<>(roleList);
        return pageBean;
    }

    public Map<String,Object> myMap(XzRole role){
        Map<String,Object> map = new HashMap<>();
        map.put("roleName",role.getRoleName());
        map.put("field1",role.getField1());
        map.put("field2",role.getField2());
        map.put("field3",role.getField3());
        return map;
    }

    @Override
    public XzRole selByRoleId(Long roleId) {
        return roleMapper.selByRoleId(roleId);
    }

    @Override
    public int update(XzRole role) {
        return roleMapper.update(role);
    }

    @Override
    public int delete(Long roleId) {
        return roleMapper.delete(roleId);
    }
}
